package ink.yql.dao;

import ink.yql.model.AddressBook;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface AddressBookDao {
    /**
     * @return 地址簿
     */
    @Select("select * from addressbook where uid=#{uid} ")
    List<AddressBook> getByUid(Integer uid);

    /**
     * @return 地址簿
     */
    @Select("select * from addressbook where uid=#{uid} and addefault=1")
    AddressBook getByUidDefault(Integer uid);

    /**
     * @return 地址簿
     */
    @Select("select * from addressbook where abid=#{abid} ")
    AddressBook getByAbid(@Param("abid") Integer abid);

    /**
     * @return 影响行数
     */
    @Insert("insert into addressbook (uid,adname,aduserName," +
              "adprovince,adcity,adaddress,adpostcode,adphone,admailbox,addefault) " +
              "values(#{uid},#{adname} ,#{aduserName} ,#{adprovince} ,#{adcity} ," +
              "#{adaddress} ,#{adpostcode} ,#{adphone},#{admailbox},#{addefault})")
    Integer addOne(AddressBook addressBook);

    /**
     * @return 影响行数
     */
    @Delete("delete from addressbook where abid = #{abid}")
    Integer deleteByAbid(@Param("abid") Integer abid);

    /**
     * @return 影响行数
     */
    @Delete("delete from addressbook where uid = #{uid}")
    Integer deleteByUid(@Param("uid") Integer uid);
    /**
     * @return 影响行数
     */
    @Update("update addressbook set where abid=#{abid}")
    Integer updateByAdid(AddressBook addressBook);

}
